package br.usp.ime.components;

import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.SessionScoped;
import br.usp.ime.entities.User;

@Component
@SessionScoped
public class WebUser {

    private User loggedInUser;

    public User getLoggedInUser() {
        return this.loggedInUser;
    }

    public void setLoggedInUser(User loggedInUser) {
        this.loggedInUser = loggedInUser;
    }

    public void login(User user) {
        this.loggedInUser = user;
    }

    public void logout() {
        this.loggedInUser = null;
    }

    public String getName() {
        return this.loggedInUser.getName();
    }

    public boolean isLoggedIn() {
        return this.loggedInUser != null;
    }
    
    public boolean isAdministrator(){
        return(isLoggedIn() && this.loggedInUser.isAdministrator());
    }

}
